import math


def qualite_clusterisation (distances, clusters):
	#evaluation la qualite de notre strategie bottom up
	#en calculant les moyennes des distances intragroupe et intergroupe
	s_intra=0.0
	s_inter=0.0
	n_intra=0.0
	n_inter=0.0
	for i in range (len(distances)):
		for j in range(len(distances[i])):
			for c in clusters:
				findI=False
				findJ=False
				for element in c:
					if element==i:
						findI=True
					elif element ==j:
						findJ=True
				if (findI==True and findJ==True):
					s_intra=s_intra+distances[i][j]
					n_intra=n_intra+1
				else : 
					s_inter=s_inter+distances[i][j]
					n_inter=n_inter+1
					
	m_intra=(s_intra/n_intra)
	m_inter=(s_inter/n_inter)
	return m_intra, m_inter